﻿using System;
using System.Linq;

using MvcCms.Data.DynamicLINQ;
using MvcCms.Service.Models;

namespace MvcCms.Service.Code.MvcCmsMobileGrid
{
    public static class MvcCmsMobileGridSort
    {
        public static IQueryable Sort(MvcCmsMobileGridRequest MvcCmsMobileGridRequest, IQueryable query)
        {
            string columnName = MvcCmsMobileGridRequest.ColumnToSortBy;
            string sortDirection = MvcCmsMobileGridRequest.SortOrder;

            if (sortDirection == "asc")
            {
                query = query.DynamicOrderBy(d => d[columnName]); 
            }
            else
            {
                query = query.DynamicOrderByDescending(d => d[columnName]); 
            }
            
            return query;
        }
    }
}
